home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Audio / GISO / Source / Sox / sbdsp.c < prev    next >
C/C++ Source or Header  |  1994-01-26  |  3KB  |  136 lines

  1. #ifndef __NeXT__
  2. #ifdef    i386
  3. /*
  4.  * Copyright 1992 Rick Richardson
  5.  * Copyright 1991 Lance Norskog And Sundry Contributors
  6.  * This source code is freely redistributable and may be used for
  7.  * any purpose.  This copyright notice must be maintained. 
  8.  * Rick Richardson, Lance Norskog And Sundry Contributors are not
  9.  * responsible for the consequences of using this software.
  10.  */
  11.  
  12. /*
  13.  * Direct to Sound Blaster device driver.
  14.  */
  15.  
  16. #include "st.h"
  17. #include <sys/types.h>
  18. #include <sys/sb.h>
  19. #include <signal.h>
  20.  
  21. /* Private data for SKEL file */
  22. typedef struct sbdspstuff {
  23.     int    samples;        /* bytes remaining in current block */
  24. } *sbdsp_t;
  25.  
  26. extern float volume, amplitude;
  27. extern int summary, verbose;
  28.  
  29. static got_int = 0;
  30.  
  31. static void
  32. sigint(s)
  33. {
  34.     if (s) got_int = 1;
  35.     else signal(SIGINT, sigint);
  36. }
  37.  
  38. /*
  39.  * Do anything required before you start reading samples.
  40.  * Read file header. 
  41.  *    Find out sampling rate, 
  42.  *    size and style of samples, 
  43.  *    mono/stereo/quad.
  44.  */
  45. sbdspstartread(ft) 
  46. ft_t ft;
  47. {
  48.     sbdsp_t sbdsp = (sbdsp_t) ft->priv;
  49.  
  50.     /* If you need to seek around the input file. */
  51.     if (0 && ! ft->seekable)
  52.         fail("SKEL input file must be a file, not a pipe");
  53.  
  54.     if (!ft->info.rate)
  55.         ft->info.rate = 11000;
  56.     ft->info.size = BYTE;
  57.     ft->info.style = UNSIGNED;
  58.     ft->info.channels = 1;
  59.     ioctl(fileno(ft->fp), DSP_IOCTL_RESET, 0);
  60.     ioctl(fileno(ft->fp), DSP_IOCTL_VOICE, 0);
  61.     ioctl(fileno(ft->fp), DSP_IOCTL_SPEED, ft->info.rate);
  62.     sigint(0);    /* Prepare to catch SIGINT */
  63. }
  64.  
  65. /*
  66.  * Read up to len samples from file.
  67.  * Convert to signed longs.
  68.  * Place in buf[].
  69.  * Return number of samples read.
  70.  */
  71.  
  72. sbdspread(ft, buf, len) 
  73. ft_t ft;
  74. long *buf, len;
  75. {
  76.     sbdsp_t sbdsp = (sbdsp_t) ft->priv;
  77.     int        rc;
  78.  
  79.     if (got_int) return (0);
  80.     rc = rawread(ft, buf, len);
  81.     if (rc < 0) return 0;
  82.     return (rc);
  83. }
  84.  
  85. /*
  86.  * Do anything required when you stop reading samples.  
  87.  * Don't close input file! 
  88.  */
  89. sbdspstopread(ft) 
  90. ft_t ft;
  91. {
  92.     /* ioctl(fileno(ft->fp), DSP_IOCTL_FLUSH, 0); */
  93. }
  94.  
  95. sbdspstartwrite(ft) 
  96. ft_t ft;
  97. {
  98.     sbdsp_t sbdsp = (sbdsp_t) ft->priv;
  99.  
  100.     /* If you have to seek around the output file */
  101.     if (0 && ! ft->seekable)
  102.         fail("Output .sbdsp file must be a file, not a pipe");
  103.  
  104.     if (!ft->info.rate)
  105.         ft->info.rate = 11000;
  106.     ft->info.size = BYTE;
  107.     ft->info.style = UNSIGNED;
  108.     ft->info.channels = 1;
  109.     ioctl(fileno(ft->fp), DSP_IOCTL_RESET, 0);
  110.     /* ioctl(fileno(ft->fp), DSP_IOCTL_FLUSH, 0); */
  111.     ioctl(fileno(ft->fp), DSP_IOCTL_VOICE, 1);
  112.     ioctl(fileno(ft->fp), DSP_IOCTL_SPEED, ft->info.rate);
  113. }
  114.  
  115. sbdspwrite(ft, buf, len) 
  116. ft_t ft;
  117. long *buf, len;
  118. {
  119.     sbdsp_t sbdsp = (sbdsp_t) ft->priv;
  120.  
  121.     if (len == 0) return 0;
  122.     return (rawwrite(ft, buf, len));
  123. }
  124.  
  125. sbdspstopwrite(ft) 
  126. ft_t ft;
  127. {
  128.     /* All samples are already written out. */
  129.     /* If file header needs fixing up, for example it needs the */
  130.      /* the number of samples in a field, seek back and write them here. */
  131.     fflush(ft->fp);
  132.     ioctl(fileno(ft->fp), DSP_IOCTL_FLUSH, 0);
  133. }
  134. #endif
  135. #endif
  136.